package cn.tedu.start.controller.customer;

import cn.tedu.commons.response.JsonResult;
import cn.tedu.pojo.customer.dto.CustomerInfDTO;
import cn.tedu.pojo.customer.entity.CustomerInf;
import cn.tedu.pojo.customer.vo.CustomerInfVO;
import cn.tedu.service.customer.ICustomerInfService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/customer/inf")
@RestController
public class CustomerInfController {
    @Autowired
    private ICustomerInfService iCustomerInfService;

    @ApiOperation("根据id查询用户信息详情")
    @PostMapping("/selectById")
    @ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long")
    public JsonResult<CustomerInf> getInfById (Long userId){
        return JsonResult.ok(iCustomerInfService.getInfById(userId));
    }

    @ApiOperation("用户添加信息")
    @PostMapping("/insert")
    public JsonResult<Void> addNew(CustomerInfDTO customerInfDTO){
        iCustomerInfService.addNew(customerInfDTO);
        return JsonResult.ok();
    }


    @ApiOperation("是否启用用户信息")
    @PostMapping("/update/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long"),
            @ApiImplicitParam(name = "isDelete",required = true,paramType = "path",dataType = "Integer")})
    public  JsonResult updateDelete(Long userId,Integer isDelete){
        iCustomerInfService.updateDelete(userId,isDelete);
        return JsonResult.ok();
    }

    @ApiOperation("更改用户信息")
    @PostMapping("/updateInf")
    @ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long")
    public  JsonResult updateInfById(CustomerInfDTO customerInfDTO){
        iCustomerInfService.updateInfById(customerInfDTO);
        return JsonResult.ok();
    }


    @ApiOperation("根据 delete查询用户信息")
    @PostMapping("/select/inf-delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId",required = true,paramType = "path",dataType = "Long"),
            @ApiImplicitParam(name = "isDelete",required = true,paramType = "path",dataType = "Integer")})
    public JsonResult<CustomerInf> getAddrByDelete(Long userId,Integer isDelete){
        CustomerInf addrByDelete = iCustomerInfService.getAddrByDelete(userId, isDelete);
        return JsonResult.ok(addrByDelete);
    }

    @ApiOperation("查询所有用户信息")
    @PostMapping("/select/all-list")
    public  JsonResult<List<CustomerInfVO>> list(){
        List<CustomerInfVO> list = iCustomerInfService.list();
        return JsonResult.ok(list);
    }




}
